<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class Config extends \app\BaseModel
{
    protected $name = "shequshop_school_config";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        if(empty($dis["uniacid"])) {
            $dis["uniacid"] = 666;
        }
        $data = $this->where($dis)->find();
        if(empty($data)) {
            $this->dataAdd($dis);
            $data = $this->where($dis)->find();
        }
        return !empty($data) ? $data->toArray() : [];
    }
    public function getCacheInfo($uniacid)
    {
        $key = "getCacheInfo_getCacheInfo" . $uniacid;
        $data = getCache($key, $uniacid);
        if(!empty($data)) {
            return $data;
        }
        $dis = ["uniacid" => $uniacid];
        $data = $this->dataInfo($dis);
        setCache($key, $data, 5, $uniacid);
        return $data;
    }
    public function getIsBus($uniacid)
    {
        $config_model = new Config();
        $config = $config_model->dataInfo(["uniacid" => $uniacid]);
        $is_bus = $config["is_bus"];
        if(!empty($input["start_time"]) && !empty($config["bus_start_time"]) && !empty($config["bus_end_time"])) {
            $z_time = strtotime(date("Y-m-d", $input["start_time"]));
            $start_time = strtotime($config["bus_start_time"]) - strtotime(date("Y-m-d", time())) + $z_time;
            $end_time = strtotime($config["bus_end_time"]) - strtotime(date("Y-m-d", time())) + $z_time;
            if($input["start_time"] < $start_time) {
                $start_time -= 86400;
                $end_time -= 86400;
            }
            $end_time = $end_time < $start_time ? $end_time + 86400 : $end_time;
            if($input["start_time"] < $start_time || $end_time < $input["start_time"]) {
                $is_bus = 0;
            }
        }
        return $is_bus;
    }
}

?>